package demo;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author tongchen
 * @create 2022-11-29 8:41
 */
@WebServlet("/req4")
public class ServletDemo8 extends ServletDemo2 {
    @Override
    protected void getMethod(ServletRequest servletRequest, ServletResponse servletResponse) {
        HttpServletRequest request=(HttpServletRequest) servletRequest;
        //1.通过map进行传参
        Map<String, String[]> map = request.getParameterMap();
        for (String key:map.keySet()) {
            System.out.print(key+" ");
            //通过key获取value
            String[] values = map.get(key);
            for (String value:values
                 ) {
                System.out.print(value+" ");
            }
            System.out.println();
        }
        System.out.println("*************************");
        //2.获取多个值
        String[] hobbies = request.getParameterValues("hobby");
        for (String value:hobbies
             ) {
            System.out.println(value);
        }

        //3.获取单个值
        String username = request.getParameter("username");
        System.out.println(username);
        String password = request.getParameter("password");
        System.out.println(password);
    }


    @Override
    protected void postMethod(ServletRequest servletRequest, ServletResponse servletResponse) {
        super.postMethod(servletRequest, servletResponse);
    }
}
